//
//  MHCHChoissort.m
//  Go!
//
//  Created by rimi on 16/7/16.
//  Copyright © 2016年 凌风. All rights reserved.
//

#import "MHCHChoissort.h"
#import "MHCHChoisTableViewCell.h"

static NSString *identifierone = @"cellone";

@interface MHCHChoissort ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) NSArray *dataArray ;
@property (nonatomic, strong) UITableView *tableview;

@end

@implementation MHCHChoissort

- (instancetype)initWithframe:(CGRect)frame Withdata:(NSArray *)array
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initializeDataSource];
        [self initializeUserInterface];
        self.dataArray = array;
        self.backgroundColor = [UIColor redColor];
    }
    return self;
}

-(void)initializeDataSource/**< 初始化数据源 */{
    

}

-(void)initializeUserInterface/**< 初始化用户界面 */{
    [self addSubview:self.tableview];

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MHCHChoisTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierone];
    cell.backgroundColor = [UIColor whiteColor];
    cell.showLabel.text = self.dataArray[indexPath.row];
    return cell;
}

-(UITableView *)tableview{
    if (!_tableview) {
        _tableview = [[UITableView alloc]initWithFrame:self.bounds];
        _tableview.delegate = self;
        _tableview.dataSource = self;
        [_tableview registerNib:[UINib nibWithNibName:@"MHCHChoisTableViewCell" bundle:nil] forCellReuseIdentifier:identifierone];
    }
    return _tableview;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if(self.dataArray.count == 3){
        [_delegate choisnaberisOkbackmessage:@{}];
    }else if (self.dataArray.count == 4){
//        筛选条件
        NSDictionary *dict1 = @{@"subcat_ids":@"944"}; /**< 五星级酒店 */
        NSDictionary *dict2 = @{@"subcat_ids":@"945"}; /**< 四星级酒店 */
        NSDictionary *dict3 = @{@"subcat_ids":@"946"}; /**< 三星级酒店 */
        NSDictionary *dict4 = @{@"subcat_ids":@"642"}; /**< 普通酒店 */
        NSArray *array = @[dict1,dict2,dict3,dict4];
        [_delegate choisstarisOkbackmessage:array[indexPath.row]];
    }else if (self.dataArray.count == 7){
        NSDictionary *dict1 = @{@"sort":@"0"}; /**< 综合查询 */
        NSDictionary *dict2 = @{@"sort":@"1"}; /**< 综合查询 */
        NSDictionary *dict3 = @{@"sort":@"2"}; /**< 综合查询 */
        NSDictionary *dict4 = @{@"sort":@"3"}; /**< 综合查询 */
        NSDictionary *dict5 = @{@"sort":@"4"}; /**< 综合查询 */
        NSDictionary *dict6 = @{@"sort":@"5"}; /**< 综合查询 */
        NSDictionary *dict7 = @{@"sort":@"6"}; /**< 综合查询 */
        NSArray *array = @[dict1,dict2,dict3,dict4,dict5,dict6,dict7];
        [_delegate choissortisOkbackmessage:array[indexPath.row]];
    }
    
    
}

@end
